CrowdTruth for Ternary Choice Tasks: Person Identification in Video

In this tutorial, we will apply CrowdTruth metrics to a binary choice crowdsourcing task for Person Identification in video fragments. The workers were asked to watch a short video fragment of about 3-5 seconds and then decide whether there is any person that appears in the video fragment. The task was executed on FigureEight. For more crowdsourcing annotation task examples, click here.

To replicate this experiment, the code used to design and implement this crowdsourcing annotation template is available here: template, css, javascript.

This is a screenshot of the task as it appeared to workers:

A sample dataset for this task is available in this file, containing raw output from the crowd on FigureEight. Download the file and place it in a folder named data that has the same root as this notebook. Now you can check your data:


In [1]:
import pandas as pd

test_data = pd.read_csv("../data/person-video-ternary-choice.csv")
test_data.head()


Out[1]:
_unit_id _created_at _id _started_at _tainted _channel _trust _worker_id _country _region ... description descriptiontags hiddeninput_gold imagelocation imagetags keyframeid_gold selected_answer_gold subtitles subtitletags videolocation
0 1856506950 8/20/2018 14:08:36 3989952315 8/20/2018 14:08:26 False imerit_india 1.0 44351094 USA LA ... NaN NaN NaN https://joran.org/ct/entity.admin.unit.2649/85... industry__c0_###_grinder__c1_###_production__c... NaN NaN Italian astronaut samantha cristoforetti uploa... Italian__0_###_astronaut__1_###_samantha__2_##... https://joran.org/ct/entity.admin.unit.2649/85...
1 1856506950 8/20/2018 15:02:01 3990045833 8/20/2018 15:01:49 False imerit_india 1.0 44399792 USA LA ... NaN NaN NaN https://joran.org/ct/entity.admin.unit.2649/85... industry__c0_###_grinder__c1_###_production__c... NaN NaN Italian astronaut samantha cristoforetti uploa... Italian__0_###_astronaut__1_###_samantha__2_##... https://joran.org/ct/entity.admin.unit.2649/85...
2 1856506950 8/20/2018 15:07:48 3990053577 8/20/2018 15:07:21 False elite 1.0 44234166 USA GA ... NaN NaN NaN https://joran.org/ct/entity.admin.unit.2649/85... industry__c0_###_grinder__c1_###_production__c... NaN NaN Italian astronaut samantha cristoforetti uploa... Italian__0_###_astronaut__1_###_samantha__2_##... https://joran.org/ct/entity.admin.unit.2649/85...
3 1856506950 8/20/2018 15:28:07 3990080202 8/20/2018 15:27:37 False instagc 1.0 44662955 GBR N4 ... NaN NaN NaN https://joran.org/ct/entity.admin.unit.2649/85... industry__c0_###_grinder__c1_###_production__c... NaN NaN Italian astronaut samantha cristoforetti uploa... Italian__0_###_astronaut__1_###_samantha__2_##... https://joran.org/ct/entity.admin.unit.2649/85...
4 1856506950 8/20/2018 15:49:46 3990104295 8/20/2018 15:49:30 False instagc 1.0 44204650 USA NH ... NaN NaN NaN https://joran.org/ct/entity.admin.unit.2649/85... industry__c0_###_grinder__c1_###_production__c... NaN NaN Italian astronaut samantha cristoforetti uploa... Italian__0_###_astronaut__1_###_samantha__2_##... https://joran.org/ct/entity.admin.unit.2649/85...

5 rows × 26 columns

Declaring a pre-processing configuration

The pre-processing configuration defines how to interpret the raw crowdsourcing input. To do this, we need to define a configuration class. First, we import the default CrowdTruth configuration class:


In [2]:
import crowdtruth
from crowdtruth.configuration import DefaultConfig

Our test class inherits the default configuration DefaultConfig, while also declaring some additional attributes that are specific to the Person Identification in Video task:

  • inputColumns: list of input columns from the .csv file with the input data
  • outputColumns: list of output columns from the .csv file with the answers from the workers
  • open_ended_task: boolean variable defining whether the task is open-ended (i.e. the possible crowd annotations are not known beforehand, like in the case of free text input); in the task that we are processing, workers pick the answers from a pre-defined list, therefore the task is not open ended, and this variable is set to False
  • annotation_vector: list of possible crowd answers, mandatory to declare when open_ended_task is False; for our task, this is a list containing true and false values
  • processJudgments: method that defines processing of the raw crowd data; for this task, we process the crowd answers to correspond to the values in annotation_vector

The complete configuration class is declared below:


In [3]:
class TestConfig(DefaultConfig):
    inputColumns = ["videolocation", "subtitles", "imagetags", "subtitletags"]
    outputColumns = ["selected_answer"]
    
    # processing of a closed task
    open_ended_task = False
    annotation_vector = ["yes", "no", "unclear"]
    
    def processJudgments(self, judgments):
        # pre-process output to match the values in annotation_vector
        for col in self.outputColumns:
            # transform to lowercase
            judgments[col] = judgments[col].apply(lambda x: str(x).lower())
        return judgments

Pre-processing the input data

After declaring the configuration of our input file, we are ready to pre-process the crowd data:


In [4]:
data, config = crowdtruth.load(
    file = "../data/person-video-ternary-choice.csv",
    config = TestConfig()
)

data['judgments'].head()


Out[4]:
output.selected_answer output.selected_answer.count output.selected_answer.unique submitted started worker unit duration job
judgment
3989952315 {u'yes': 1, u'no': 0, u'unclear': 0} 1 3 2018-08-20 14:08:36 2018-08-20 14:08:26 44351094 1856506950 10 ../data/person-video-ternary-choice
3990045833 {u'yes': 1, u'no': 0, u'unclear': 0} 1 3 2018-08-20 15:02:01 2018-08-20 15:01:49 44399792 1856506950 12 ../data/person-video-ternary-choice
3990053577 {u'yes': 1, u'no': 0, u'unclear': 0} 1 3 2018-08-20 15:07:48 2018-08-20 15:07:21 44234166 1856506950 27 ../data/person-video-ternary-choice
3990080202 {u'yes': 1, u'no': 0, u'unclear': 0} 1 3 2018-08-20 15:28:07 2018-08-20 15:27:37 44662955 1856506950 30 ../data/person-video-ternary-choice
3990104295 {u'yes': 1, u'no': 0, u'unclear': 0} 1 3 2018-08-20 15:49:46 2018-08-20 15:49:30 44204650 1856506950 16 ../data/person-video-ternary-choice

Computing the CrowdTruth metrics

The pre-processed data can then be used to calculate the CrowdTruth metrics:


In [5]:
results = crowdtruth.run(data, config)

results is a dict object that contains the quality metrics for the video fragments, annotations and crowd workers.

The video fragment metrics are stored in results["units"]:


In [6]:
results["units"].head()


Out[6]:
duration input.imagetags input.subtitles input.subtitletags input.videolocation job output.selected_answer output.selected_answer.annotations output.selected_answer.unique_annotations worker uqs unit_annotation_score uqs_initial unit_annotation_score_initial
unit
1856506950 29.85 industry__c0_###_grinder__c1_###_production__c... Italian astronaut samantha cristoforetti uploa... Italian__0_###_astronaut__1_###_samantha__2_##... https://joran.org/ct/entity.admin.unit.2649/85... ../data/person-video-ternary-choice {u'yes': 20, u'unclear': 0, u'no': 0} 20 1 20 1.0 {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0} 1.0 {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0}
1856506951 9.60 man__c0_###_soccer__c1_###_portrait__c2_###_pe... this phenomena is it's massive the phenomena__0_###_massive__1_###_ https://joran.org/ct/entity.admin.unit.2649/85... ../data/person-video-ternary-choice {u'yes': 20, u'unclear': 0, u'no': 0} 20 1 20 1.0 {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0} 1.0 {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0}
1856506952 12.85 people__c0_###_man__c1_###_adult__c2_###_portr... around could the lights be coming from lights__0_###_coming__1_###_ https://joran.org/ct/entity.admin.unit.2649/85... ../data/person-video-ternary-choice {u'yes': 20, u'unclear': 0, u'no': 0} 20 1 20 1.0 {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0} 1.0 {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0}
1856506953 38.45 water__c0_###_no person__c1_###_ocean__c2_###_... when investigators map the coordinates onto lo... investigators__0_###_map__1_###_coordinates__2... https://joran.org/ct/entity.admin.unit.2649/85... ../data/person-video-ternary-choice {u'yes': 0, u'unclear': 0, u'no': 20} 20 1 20 1.0 {u'yes': 0.0, u'unclear': 0.0, u'no': 1.0} 1.0 {u'yes': 0.0, u'unclear': 0.0, u'no': 1.0}
1856506954 20.00 sky__c0_###_no person__c1_###_power__c2_###_el... the bright lights are part of a bright lights__0_###_ https://joran.org/ct/entity.admin.unit.2649/85... ../data/person-video-ternary-choice {u'yes': 0, u'unclear': 0, u'no': 20} 20 1 20 1.0 {u'yes': 0.0, u'unclear': 0.0, u'no': 1.0} 1.0 {u'yes': 0.0, u'unclear': 0.0, u'no': 1.0}

The uqs column in results["units"] contains the video fragment quality scores, capturing the overall workers agreement over each video fragment. Here we plot its histogram:


In [7]:
import matplotlib.pyplot as plt
%matplotlib inline

plt.hist(results["units"]["uqs"])
plt.xlabel("Video Fragment Quality Score")
plt.ylabel("Video Fragment")


Out[7]:
Text(0,0.5,u'Video Fragment')

The unit_annotation_score column in results["units"] contains the video fragment-annotation scores, capturing the likelihood that an annotation is expressed in a video fragment. For each video fragment, we store a dictionary mapping each annotation to its video fragment-relation score.


In [8]:
results["units"]["unit_annotation_score"].head()


Out[8]:
unit
1856506950    {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0}
1856506951    {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0}
1856506952    {u'yes': 1.0, u'unclear': 0.0, u'no': 0.0}
1856506953    {u'yes': 0.0, u'unclear': 0.0, u'no': 1.0}
1856506954    {u'yes': 0.0, u'unclear': 0.0, u'no': 1.0}
Name: unit_annotation_score, dtype: object

The worker metrics are stored in results["workers"]:


In [9]:
results["workers"].head()


Out[9]:
duration job judgment unit wqs wwa wsa wqs_initial wwa_initial wsa_initial
worker
1924522 16.000000 1 25 25 0.853980 0.913554 0.934789 0.776666 0.865263 0.897607
3587109 18.360000 1 25 25 0.959812 0.968868 0.990653 0.930607 0.947368 0.982308
4316379 26.600000 1 25 25 0.856224 0.917710 0.933001 0.812911 0.888421 0.915006
5203616 17.333333 1 18 18 0.959504 0.967514 0.991721 0.933497 0.947368 0.985357
6330997 25.360000 1 25 25 0.880053 0.932054 0.944208 0.822818 0.896842 0.917462

The wqs columns in results["workers"] contains the worker quality scores, capturing the overall agreement between one worker and all the other workers.


In [10]:
plt.hist(results["workers"]["wqs"])
plt.xlabel("Worker Quality Score")
plt.ylabel("Workers")


Out[10]:
Text(0,0.5,u'Workers')

The annotation metrics are stored in results["annotations"]. The aqs column contains the annotation quality scores, capturing the overall worker agreement over one relation.


In [11]:
results["annotations"]


Out[11]:
output.selected_answer aqs aqs_initial
no 1000 9.292260e-01 8.971413e-01
unclear 1000 1.000000e-08 1.000000e-08
yes 1000 9.447522e-01 9.168397e-01